package com.yuan.farmerwork.ynblog.config;

import com.yuan.farmerwork.ynblog.utils.constants.CommConstants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web应用相关配置.
 *
 * @author JsY
 * @date 2020-03-25 09:21
 * @since 0.0.1-SNAPSHOT
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

    /**
     * 在配置文件中配置的文件保存路径
     */
    @Value("${img.location}")
    private String folder;

    /**
     * 设置拦截请求资源.
     *
     * @param registry 注册
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(CommConstants.URL_UPLOAD)
                .addResourceLocations(CommConstants.RELATIVE_FILE + folder);
    }
}
